#include <iostream>
#include <thread>

#include "../include/threadsafe_lookup_table.h"

threadsafe_lookup_table<int, int> table;

void insert(int key, int value) {
    table.add_or_update_mapping(key, value);
}

int main(int argc, char* argv[]) {
    table.add_or_update_mapping(1, 2);
    std::cout << table.value_for(1, 3) << std::endl;
    table.remove_mapping(1);
    std::cout << table.value_for(1, 3) << std::endl;

    std::vector<std::thread> threads;

    for (int i = 0; i < 10; i++) {
        threads.emplace_back(insert, i, i + 1);
    }

    for (auto& thread : threads) thread.join();

    for (int i = 0; i < 10; i++) {
        std::cout << table.value_for(i, -1) << std::endl;
    }

    std::thread t1(insert, 2, 3);
    std::thread t2(insert, 2, 4);
    std::thread t3(insert, 2, 5);

    t1.join();
    t2.join();
    t3.join();

    std::cout << table.value_for(2) << std::endl;

    return 0;
}